<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>订单详情</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>
</head>
<body class="">
    <header class="header">
        <div class="backPrevPage" onclick="historyBack()"></div>
        <div class="pageTitle">订单详情</div>
    </header>
    <section class="OrderDetailsInfoPage HTML_BOX">
        <div class="odBox1">
            <ul>
                <li>订单编号：<span id="order_no">1023566656521527</span></li>
                <li>下单时间：<span id="order_time">2018-7-5 17:02</span></li>
            </ul>
            <div class="btn1 oder_type f_c">待支付</div><!-- 除了已取消，全部用这个样式 -->
            <!-- <div class="btn2 f_c">已取消</div> -->
        </div>
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <ul class="settings plr bg-fff">
            <li class="displayFlex">
                <span>收货人</span>
                <span id="address_name">陈晓晓</span>
            </li>
            <li class="displayFlex">
                <span>电话</span>
                <span id="address_phone">197***2547</span>
            </li>
            <li class="displayFlex">
                <span>邮箱</span>
                <span id="address_email">3433@qq.com</span>
            </li>
            <li class="displayFlex">
                <span>地址</span>
                <span id="address_detail">重庆南坪贝蒂龙A座14-2</span>
            </li>
        </ul>
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <div class="odBox2">
            <div class="deliveryTime displayFlex">
                <span>希望配送时间</span>
                <span>2018-12-5</span>
            </div>
            <ul class="order_ware">
                <li class="wareInfo">
                    <div class="wareImage">
                        <img src="../image/testsp.png" />
                    </div>
                    <div class="wareData">
                        <div class="wareName">广西车厘子</div>
                        <div class="wareGuiGe">2kg<i></i></div>
                        <div class="warePrice">
                            <div><span class="prcie1">$62.00</span><del class="prcie2">$45.00</del></div>
                            <span class="count">x1</span>
                        </div>
                    </div>
                </li>
                <li class="wareInfo">
                    <div class="wareImage">
                        <img src="../image/testsp.png" />
                    </div>
                    <div class="wareData">
                        <div class="wareName">广西车厘子</div>
                        <div class="wareGuiGe">2kg<i></i></div>
                        <div class="warePrice">
                            <div><span class="prcie1">$62.00</span><del class="prcie2">$45.00</del></div>
                            <span class="count">x1</span>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <ul class="odBox3">
            <li>
                <span>商品金额</span>
                <div id="" class="">$0</div>
            </li>
            <li>
                <span>GST/HST</span>
                <div id="g_sui" class="">$0</div>
            </li>
            <li>
                <span>PST</span>
                <div id="p_sui" class="">$0</div>
            </li>
            <li>
                <span>优惠金额</span>
                <div id="" class="">$0</div>
            </li>
            <li>
                <span>运费</span>
                <div id="" class="">$0</div>
            </li>
            <li>
                <span>优惠券金额</span>
                <div id="" class="">$0.00</div>
            </li>
            <li class="tol">
                <span>实付金额</span>
                <div class="c_main">$124.00</div>
            </li>
        </ul>
        <div class="bg-eee" style="border-bottom:.43rem solid #EEE ; "></div>
    </section>
    <section class="orderFoot">
        <!-- <div class="oder_type"></div> -->
        <!-- 所有的按钮样式 -->
        <div style="display: flex">
            <div class="order_btn go_pay f_c"></div>
            <div class="order_btn2 f_c"></div>
        </div>

    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">

    var param = {};
    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        ifCnAndEn();
        param = api.pageParam ||{id:0};
        ready();
    };

    function ready(){
        getAjax(Interface.order_detail,{id:param.id},function(res){
            console.log(JSON.stringify(res));
            var o = res.data.order;
            orderBtn(res.data.order_type,o);
            var list = res.data.list;
            $("#order_no").html(o.order_number);
            $("#order_time").html(timestampToTime(o.create_time));
           if(cnen==2){
               res.data.order_type = res.data.enorder_type;
            }
            $(".oder_type").html(res.data.order_type);
            $("#address_name").html(o.accept_name);
            $("#address_phone").html(o.mobile);
            $("#address_email").html(o.email);
            $("#address_detail").html(o.address);
            $("#reach_date").html(o.reach_date);
            $(".odBox3 li").eq(0).find("div").html('$'+Number(o.pay_price).toFixed(2));
            $(".odBox3 li").eq(1).find("div").html('$'+Number(o.g_shui).toFixed(2));
            $(".odBox3 li").eq(2).find("div").html('$'+Number(o.p_shui).toFixed(2));
            $(".odBox3 li").eq(3).find("div").html('$'+Number(o.youhui_price).toFixed(2));
            $(".odBox3 li").eq(4).find("div").html('$'+Number(o.send_price).toFixed(2));
            $(".odBox3 li").eq(5).find("div").html('$'+Number(o.coupon_price).toFixed(2));
            $(".odBox3 li").eq(6).find("div").html('$'+Number(o.pay_price).toFixed(2));
            var html ='';
            console.log(JSON.stringify(list));
            $.each(list,function(j,jtem){
                var name = '';
                if(cnen==1){
                    name = jtem.title;
                }else{
                    name = jtem.egname;
                }
                html+='<li onclick="goWare(\''+jtem.product_id+'\')" class="wareInfo">';
                    html+='<div class="wareImage"><img src="'+getImg(jtem.icon)+'" /></div>';
                    html+='<div class="wareData">';
                        html+='<div class="wareName">'+name+'</div>';
                        //html+='<div class="wareGuiGe">2kg</div>';
                        html+='<div class="warePrice">';
                        // if(jtem.old_price == ""){
                        //     html+='<div><span class="prcie1">$'+jtem.new_price+'</span></div>';
                        //     html+='<span>x'+jtem.num+'</span>';
                        // }else{
                        //     html+='<div><span class="prcie1">$'+jtem.new_price+'</span><del class="prcie2">$'+jtem.old_price+'</del></div>';
                        //     html+='<span>x'+jtem.num+'</span>';
                        // }
                         html+='<div><span class="prcie1">$'+jtem.one_price+'</span></div>';
                            html+='<span>x'+jtem.num+'</span>';
                        html+='</div>';
                    html+='</li>';
            })
            $(".order_ware").html(html);


        },function(res,err){})
    }
    //去付款
    function go_pay(id,price){
        event.stopPropagation();
        var p = {
            order_number:id,
            sum_price:price,
        }
        openWin('ware_payOrder','ware_payOrder.html',p);
    }
    //确认付款
    function recived_sure(id){
        getAjax(Interface.recived_sure,{token:token,order_id:id},function(res){
            pop.msg(res.msg);
            api.sendEvent({
                name: 'duihuanyhq',
                extra: {}
            });
            historyBack();
        },function(res,err){})
    }
    function go_eva(id){
        event.stopPropagation();
        openWin('order_chooseEva','order_chooseEva.html',{order_id:id});
    }
    function orderBtn(type,item){
        var html ='';
        console.log(type);
        if(type == '待付款'){
            $(".order_btn").addClass("btn1");
            if(cnen==1){
                $(".order_btn").html('去付款');
            }else{
                $(".order_btn").html('Go pay');
            }
            $(".order_btn").attr("onclick",'go_pay('+item.order_number+','+item.pay_price+')');
        }else if(type == '待发货'){
            // $(".order_btn").addClass("btn1");
            // if(cnen==1){
            //     $(".order_btn").html('确认收货');

            // }else{
            //     $(".order_btn").html('Confirm receipt');
            // }
            // $(".order_btn").attr("onclick",'recived_sure('+item.id+')');
        }else if(type == '待评价'){
            $(".order_btn").addClass("btn2");
            $(".order_btn2").removeClass("dn").addClass("btn1");
            if(cnen==1){
                $(".order_btn").html('再次购买');
                $(".order_btn2").html('评价');
                html+='<div class="btn2 go_ware f_c">再次购买</div>';
                html+='<div onclick="go_eva('+item.id+');" class="btn1 pingjia f_c">评价</div>';
            }else{
                $(".order_btn").html('Buy again');
                $(".order_btn2").html('Review');
            }
            $(".order_btn2").attr("onclick",'go_eva('+item.id+')');

        }else if(type == '订单已取消'){
            html+='<div class="btn2 go_ware f_c">Buy Again</div>';
        }
        return html;
    }



    function timestampToTime(timestamp) {
    //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var date = new Date(timestamp * 1000);
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
        h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours())+ ':';
        m = (date.getMinutes()< 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
        s = date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds();
        return Y+M+D+h+m+s;
    }
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
            $(".pageTitle").html('Order Detail');
            $(".odBox1 ul li").eq(0).html('Order No: <span id="order_no"></span>');
            $(".odBox1 ul li").eq(1).html('Order Time: <span id="order_time"></span>');
            $(".settings li").eq(0).find("span").eq(0).html('Name');
            $(".settings li").eq(1).find("span").eq(0).html('Phone Number');
            $(".settings li").eq(2).find("span").eq(0).html('Email');
            $(".settings li").eq(3).find("span").eq(0).html('Address');
            $(".deliveryTime span").eq(0).html('Select Delivery Date');
            $(".odBox3 li").eq(0).find("span").html('Total Amount');
            $(".odBox3 li").eq(3).find("span").html('Discount');
            $(".odBox3 li").eq(4).find("span").html('Shipping Fee');
            $(".odBox3 li").eq(5).find("span").html('Coupon Discount');
            $(".odBox3 li").eq(6).find("span").html('Paid');
        }
    }
</script>
</html>
